package com.api.tag.createtag;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.api.test.AssertApi;
import com.api.test.UrnType;
import com.zyncro.api.ITagApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.ObjectResultApi;
import com.zyncro.api.model.TagApi;
import com.zyncro.api.model.TagApiType;

@ContextConfiguration(locations = { "classpath:/tags/tags-context.xml" })
public class CreateTagAdministrator extends AbstractApiTest {

	@Value("#{tagtest['user.administrator'].appId}")
	private String adminUrn;

	@Value("#{tagtest['user.administrator'].password}")
	private String adminPassword;

	@BeforeClass
	protected void setParameters() throws Exception {

		getApi().login(adminUrn, adminPassword);
	}

	@Test
	public void testCreateCategory() throws ZyncroApiException {

		String name = "Helooooooou";

		ObjectResultApi<TagApi> result = getApi().getService(ITagApiService.class).createTag(name, TagApiType.CATEGORY);
		TagApi tagApi = result.getObject();

		Assert.assertEquals(tagApi.getTagType(), TagApiType.CATEGORY.getId(), "Tag api type");
		Assert.assertNull(tagApi.getMember(), "Tag member");
		AssertApi.assertUrnType(tagApi.getUrn(), UrnType.GROUP);
	}

	@Test
	public void testCreateLocation() throws ZyncroApiException {

		String name = "Helooooooou";

		ObjectResultApi<TagApi> result = getApi().getService(ITagApiService.class).createTag(name, TagApiType.LOCATION);
		TagApi tagApi = result.getObject();

		Assert.assertEquals(tagApi.getTagType(), TagApiType.LOCATION.getId(), "Tag api type");
		Assert.assertNull(tagApi.getMember(), "Tag member");
		AssertApi.assertUrnType(tagApi.getUrn(), UrnType.GROUP);
	}
}
